home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-06-30 | 11.8 KB | 417 lines | [TEXT/CWIE] |
- // ===========================================================================
- // LAGASquareVSlider.cp
- // ===========================================================================
- // “Apple Grayscale Appearance” compliant vertical slider control with rectangular indicator
- // Copyright © 1996 Chrisoft (Christophe ANDRES) All rights reserved.
- //
- // You may use this source code in any application (commercial, shareware, freeware,
- // postcardware, etc), but not remove this notice (no need to acknowledge the use of
- // this class in the about box)
- // You may not sell this source code in any form. This source code may be placed on
- // publicly accessable archive sites and source code disks. It may not be placed on
- // profit archive sites and source code disks without the permission of the author,
- // Christophe ANDRES.
- //
- // This source code is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- //
- // If you make any change or improvement on this class, please send the improved/changed
- // version to : chrisoft@calva.net or Christophe ANDRES
- // 20, rue Prosper Mérimée
- // 67100 STRASBOURG
- // FRANCE
- //
- // ===========================================================================
- // LAGASquareVSlider.h <- double-click + Command-D to see class declaration
- //
- // LAGASquareVSlider is my implementation of the “Apple Grayscale Appearance for System 7.5”
- // vertical square slider control
- //
- // This class requires LAGASliderBase.cp to be present in your project
- // This class requires AGAColors.cp to be present in your project
- //
- // Version : 1.2
- //
- // Change History (most recent first, date in US form : mm/dd/yy):
- //
- // 06/30/96 ca Public release of version 1.2
- // 06/27/96 ca Changed checks for disabled state (check on triState_On instead of triState_Off)
- // in order that triState_Latent state is drawn as disabled
- // 06/04/96 ca Added RegisterClass method to ease registry
- // Increased version to 1.2
- // 05/16/96 ca class made available by Christophe ANDRES <chrisoft@calva.net>
- // (version 1.1)
- //
- // To Do:
- //
-
- #include "LAGASquareVSlider.h"
- #include "AGAColors.h"
- #include <UDrawingState.h>
- #include <PP_Types.h>
-
- // begin <06/04/96 ca>
- void LAGASquareVSlider::RegisterClass ()
-
- {
- URegistrar::RegisterClass(LAGASquareVSlider::class_ID, (ClassCreatorFunc)LAGASquareVSlider::CreateAGASquareVSliderStream);
- }
- // end <06/04/96 ca>
-
- LAGASquareVSlider* LAGASquareVSlider::CreateAGASquareVSliderStream (LStream *inStream)
-
- {
- return(new LAGASquareVSlider(inStream));
- }
-
- //-------Constructors-------------------------------------------------------------------------------------------------
-
- LAGASquareVSlider::LAGASquareVSlider ()
-
- {
- mTrackOriginTinkering = 1;
- }
-
- LAGASquareVSlider::LAGASquareVSlider (LStream *inStream) : LAGASliderBase(inStream)
-
- {
- mTrackOriginTinkering = 1;
- }
-
- LAGASquareVSlider::LAGASquareVSlider (const LAGASquareVSlider &inOriginal) : LAGASliderBase(inOriginal)
-
- {
- mTrackOriginTinkering = 1;
- }
-
- LAGASquareVSlider::LAGASquareVSlider (const SPaneInfo &inPaneInfo, MessageT inValueMessage, Boolean inBottomRightPointer,
- Int32 inInitialValue, Int32 inMinValue, Int32 inMaxValue)
- : LAGASliderBase(inPaneInfo, inValueMessage, true, inBottomRightPointer, inInitialValue,
- inMinValue, inMaxValue)
- {
- mTrackOriginTinkering = 1;
- }
-
- //-------Drawers----------------------------------------------------------------------------------------------------
-
-
- void LAGASquareVSlider::DrawIndicator (Boolean inPushed)
-
- {
- StColorPenState theState;
- Boolean hasColor = ::PaneInColor(this);
- Boolean disabled = (mEnabled != triState_On); // <06/27/96 ca>
- Rect frame;
-
- theState.Normalize();
- CalcLocalFrameRect(frame);
-
- short position = GetIndicatorPosition();
-
- //short origin = (mRightBottomPointing ? frame.left : frame.right - 1);
-
- ::SetRect(&frame, frame.left, position - 6, frame.left + 16, position + 7);
- if (hasColor)
- ::RGBBackColor(&gAGAColorArray[2]);
- EraseRect(&frame);
-
- if (hasColor && !disabled)
- {
- Rect r = frame;
- InsetRect(&r, 1, 1);
- ::RGBBackColor((inPushed ? &gAGAColorArray[8] : &gAGAColorArray[5]));
- EraseRect(&r);
- }
- if (disabled)
- if (hasColor)
- ::RGBForeColor(&gAGAColorArray[8]);
- else
- PenPat(&qd.gray);
- ::MoveTo(frame.left, position - 5);
- ::Line(0, 10);
- ::Move(1, 1); ::Line(13, 0);
- ::Move(1, -1); ::Line(0, -10);
- ::Move(-1, -1); ::Line(-13, 0);
- if (hasColor)
- {
- ::RGBForeColor((disabled ? &gAGAColorArray[1] : (inPushed ? &gAGAColorArray[5] : &gAGAColorArray[3])));
- ::Move(1, 1); ::Line(11, 0);
- ::Move(-12, 1); ::Line(0, 8);
- ::RGBForeColor((disabled ? &gAGAColorArray[4] : (inPushed ? &gAGAColorArray[10] : &gAGAColorArray[8])));
- ::Move(1, 1); ::Line(12, 0);
- ::Line(0, -9);
- ::RGBForeColor((disabled ? &gAGAColorArray[W] : (inPushed ? &gAGAColorArray[3] : &gAGAColorArray[1])));
- ::Move(-13, -1); ::Line(0, 0);
- }
- if (!disabled)
- {
- if (hasColor)
- {
- ::Move(3, 2); ::Line(0, 0);
- ::Move(0, 2); ::Line(0, 0);
- ::Move(0, 2); ::Line(0, 0);
- ::RGBForeColor((inPushed ? &gAGAColorArray[12] : &gAGAColorArray[10]));
- }
- else
- ::Move(2, 7);
- ::Move(1, 1); ::Line(6, 0);
- ::Move(0, -2); ::Line(-6, 0);
- ::Move(0, -2); ::Line(6, 0);
- if (hasColor)
- {
- ::RGBForeColor((inPushed ? &gAGAColorArray[5] : &gAGAColorArray[3]));
- ::Move(-1, -1); ::Line(-5, 0);
- ::Move(0, 2); ::Line(5, 0);
- ::Move(0, 2); ::Line(-5, 0);
- }
- }
- }
-
- Int16 LAGASquareVSlider::FindHotSpot (Point inPoint)
-
- {
- Rect frame;
-
- // The only hot spot we know of in a slider is the pointer
- GetIndicatorRect(frame);
-
- return(::PtInRect(inPoint, &frame) ? 1 : 0);
- }
-
- Boolean LAGASquareVSlider::PointInHotSpot (Point inPoint, Int16 inHotSpot)
-
- {
- Rect frame;
-
- // The only hot spot we know of in a slider is the pointer
- GetIndicatorRect(frame);
-
- return(::PtInRect(inPoint, &frame));
- }
-
- short LAGASquareVSlider::GetIndicatorPosition ()
-
- {
- Rect frame;
-
- CalcLocalFrameRect(frame);
- double size = (frame.bottom - frame.top) - 20;
- double division = size / (double)(mMaxValue - mMinValue);
-
- return(frame.bottom - 10 - ((mValue - mMinValue) * division));
- }
-
- void LAGASquareVSlider::GetIndicatorRect (Rect &outRect)
-
- {
- Rect frame;
-
- CalcLocalFrameRect(frame);
- short position = GetIndicatorPosition();
-
- ::SetRect(&outRect, frame.left, position - 6, frame.left + 16, position + 7);
- }
-
- void LAGASquareVSlider::InitializeGhost ()
-
- {
- Boolean hasColor = ::PaneInColor(this);
- Rect r;
-
- LAGASliderBase::InitializeGhost();
-
- mGhostPointer->BeginDrawing();
-
- if (hasColor)
- ::RGBBackColor(&gAGAColorArray[2]);
- ::SetRect(&r, 0, 0, 16, 13);
- ::EraseRect(&r);
-
- if (hasColor)
- ::RGBForeColor(&gAGAColorArray[7]);
- ::MoveTo(0, 1); ::Line(0, 10);
- ::Move(1, 1); ::Line(13, 0);
- ::Move(1, -1); ::Line(0, -10);
- ::Move(-1, -1); ::Line(-13, 0);
- if (hasColor)
- {
- ::RGBForeColor(&gAGAColorArray[11]);
- ::Move(4, 0); ::Line(0, 0);
- ::Move(4, 0); ::Line(0, 0);
- ::Move(0, 12); ::Line(0, 0);
- ::Move(-4, 0); ::Line(0, 0);
- ::RGBForeColor(&gAGAColorArray[7]);
- ::Move(0, -1); ::Line(0, 0);
- ::Move(4, 0); ::Line(0, 0);
- ::RGBForeColor(&gAGAColorArray[5]);
- ::Move(0, -1); ::Line(0, -1);
- ::Move(-4, 1); ::Line(0, -1);
- ::Move(1, -1); ::Line(2, 0);
- ::Move(2, 0); ::Line(1, 0);
- ::Move(0, -2); ::Line(-1, 0);
- ::Move(-2, 0); ::Line(-2, 0);
- ::Move(0, -2); ::Line(2, 0);
- ::Move(2, 0); ::Line(1, 0);
- ::Move(-2, -2); ::Line(0, 0);
- ::Move(-4, 0); ::Line(0, 0);
- ::RGBForeColor(&gAGAColorArray[9]);
- ::Move(0, 2); ::Line(0, 0);
- ::Move(0, 2); ::Line(0, 0);
- ::Move(0, 2); ::Line(0, 0);
- ::Move(4, 0); ::Line(0, 0);
- ::Move(0, -2); ::Line(0, 0);
- ::Move(0, -2); ::Line(0, 0);
- ::ForeColor(whiteColor);
- ::Move(1, -1); ::Line(0, 0);
- ::Move(-2, 0); ::Line(-2, 0);
- ::Move(-2, 0); ::Line(0, 0);
- ::Move(0, 2); ::Line(0, 0);
- ::Move(2, 0); ::Line(2, 0);
- ::Move(2, 0); ::Line(0, 0);
- ::Move(0, 2); ::Line(0, 0);
- ::Move(-2, 0); ::Line(-2, 0);
- ::Move(-2, 0); ::Line(0, 0);
- ::Move(-3, 3); ::Line(0, -8);
- ::Move(1, -1); ::Line(2, 0);
- ::Move(2, 0); ::Line(2, 0);
- ::Move(2, 0); ::Line(2, 0);
- }
- mGhostPointer->EndDrawing();
-
- // Define a region to draw the pointer nicely if the ghost passes on its top
- mGhostMask = ::NewRgn();
- ::OpenRgn();
- ::MoveTo(0, 1); ::Line(0, 11);
- ::Line(1, 1); ::Line(13, 0);
- ::Line(2, -2); ::Line(0, -10);
- ::Line(-2, -1); ::Line(-13, 0);
- ::Line(-1, 1);
- ::CloseRgn(mGhostMask);
- }
-
- void LAGASquareVSlider::DrawGhost (Point inPoint)
-
- {
- Rect frame;
- short position;
-
- if (inPoint.v != mLastPosition.v)
- {
- Rect indicRect, overStep;
-
- CalcLocalFrameRect(frame);
- double size = (frame.bottom - frame.top) - 20;
- double division = size / (double)(mMaxValue - mMinValue);
-
- short MaxPt = frame.bottom - 10 - ((mMaxValue - mMinValue) * division);
- short MinPt = frame.bottom - 10;
- if (inPoint.v < MaxPt)
- position = MaxPt;
- else
- if (inPoint.v > MinPt)
- position = MinPt;
- else
- position = inPoint.v;
-
- frame.right = frame.left + 16;
- frame.top = position - 6;
- frame.bottom = frame.top + 13;
-
- if (!::EmptyRect(&mLastGhost))
- {
- indicRect = mLastGhost;
- StClipRgnState clip;
-
- if (indicRect.top < frame.top)
- {
- if (indicRect.bottom > frame.top)
- indicRect.bottom = frame.top;
- }
- else
- {
- if (frame.bottom > indicRect.top)
- indicRect.top = frame.bottom;
- }
- clip.ClipToIntersection(indicRect);
- ::RGBBackColor(&gAGAColorArray[2]);
- ::EraseRect(&mLastGhost);
- DrawSlideTrack();
- GetIndicatorRect(indicRect);
- if (::SectRect(&indicRect, &mLastGhost, &overStep))
- DrawIndicator(true);
- }
-
- StColorPenState theState;
- theState.Normalize();
- mGhostPointer->CopyImage(GetMacPort(), frame);
-
- if ((!::EmptyRect(&overStep)) && (mGhostMask != nil))
- {
- StClipRgnState clip;
- ::OffsetRgn(mGhostMask, -(*mGhostMask)->rgnBBox.left, -(*mGhostMask)->rgnBBox.top);
- ::OffsetRgn(mGhostMask, frame.left, frame.top);
- RgnHandle theClipRegion = ::NewRgn();
- GetIndicatorRect(indicRect);
- ::RectRgn(theClipRegion, &indicRect);
- ::DiffRgn(theClipRegion, mGhostMask, theClipRegion);
- clip.ClipToIntersectionRgn(theClipRegion);
- DrawIndicator(true);
- }
- mLastGhost = frame;
- mLastPosition = inPoint;
- }
- }
-
- void LAGASquareVSlider::FinishTrackHotSpot (Point inPoint)
-
- {
- Boolean hasColor = ::PaneInColor(this);
- Rect frame, indicRect;
- short newValue;
-
- CalcLocalFrameRect(frame);
- double size = (frame.bottom - frame.top) - 20;
- double division = size / (double)(mMaxValue - mMinValue);
-
- short MaxPt = frame.bottom - 10 - ((mMaxValue - mMinValue) * division);
- short MinPt = frame.bottom - 10;
- if (inPoint.v <= MaxPt)
- newValue = mMaxValue;
- else
- if (inPoint.v >= MinPt)
- newValue = mMinValue;
- else
- {
- newValue = ((MinPt - inPoint.v) / division) + mMinValue;
- short lowPos = frame.bottom - 11 - (newValue * division);
- short highPos = frame.bottom - 11 - ((newValue + 1) * division);
- if ((lowPos - inPoint.v) > (inPoint.v - highPos))
- newValue++;
- }
-
- if (newValue != mValue)
- {
- StClipRgnState clip;
- clip.Normalize();
- GetIndicatorRect(indicRect);
- if (hasColor)
- ::RGBBackColor(&gAGAColorArray[2]);
- ::EraseRect(&indicRect);
- ::EraseRect(&mLastGhost);
- DrawSlideTrack();
- // Update our control value and Broadcast it
- SetValue(newValue);
- }
- else
- {
- if (hasColor)
- ::RGBBackColor(&gAGAColorArray[2]);
- ::EraseRect(&mLastGhost);
- DrawSlideTrack();
- }
- // We dont redraw the pointer here, because it will anyway be redrawn in the unpressed state
- // in the method LAGASliderBase::HotSpotResult
- }
-
-